package com.chuji.crmcj.act;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.chuji.crmcj.R;
import com.chuji.crmcj.utils.SPUtils;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.UrlUtils;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

public class FeedBackActivity extends BaseActivity {
    /*用户的建议*/
    private EditText et_feedback;
    /*提交*/
    private Button btn_submit;
    /*返回*/
    private ImageView iv_back;
    private LinearLayout ll_main;
    //用户Id
    String SalesID;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        iv_back= (ImageView) findViewById(R.id.iv_Back);
        ll_main= (LinearLayout) findViewById(R.id.ll_main);
        et_feedback= (EditText) findViewById(R.id.et_feedback);
        btn_submit= (Button) findViewById(R.id.btn_submit);
        ll_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //收起软键盘
                InputMethodManager imm = (InputMethodManager)
                        getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        });
        /**
         * 返回
         */
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        /**
         * 提交用户反馈建议
         */
        btn_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //将用户输入的信息上传到服务器
                new Thread() {
                    public void run() {
                        //获取用户输入
                        final String Content=et_feedback.getText().toString();
                        //获取用户UserId
                        SalesID = SPUtils.getString(FeedBackActivity.this, "UserID", "");
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("Content",Content);
                        map.put("SalesID",SalesID);
                        postRequest(UrlUtils.SUBMIT_FEEDBACK, map, new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject jsonObject) {
                                UIUtils.showToastSafe("提交成功");
                            }
                        });
                    }
                }.start();

            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }
}
